package com.burgess.net.mirrored;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * Mirrored Queues
 *  修改配置broker配置，启用镜像
 * 创建人    BurgessLee
 * 创建时间   2020/5/31
 * 描述
 */
public class MirroredQueuesSender {

    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        Connection connection = activeMQConnectionFactory.createConnection();

        Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);

        Destination destination = session.createQueue("mirrored-queue");
        MessageProducer producer = session.createProducer(destination);

        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        connection.start();

        for(int i = 0 ; i < 3; i ++){
            TextMessage textMessage = session.createTextMessage("message--" + i);

            // 通过消费生产者发出消息
            producer.send(textMessage);
        }

        session.commit();
        session.close();
        connection.close();
    }

}
